#!/bin/bash 
# 
# 本文件编辑时，需要再gitee在线编辑，不要在本地编辑，以免增加windows的crlf字符导致wget失败
# 初始化运行环境
echo '下载 properties.jar : '$propertiesDownUrl
wget $propertiesDownUrl -O ~/properties.jar
cd ~
# 安装jak、tomcat
# 创建存放下载文件的文件夹 /readyFile
echo '开始安装jdk、tomcat'
mkdir /readyFile
cd /readyFile
# 下载jdk并安装
echo '下载jdk';
wget http://down.zvo.cn/centos/jdk-8u73-linux-x64.rpm
rpm -ivh jdk-8u73-linux-x64.rpm
echo 'export JAVA_HOME=/usr/java/jdk1.8.0_73/'>>/etc/profile
echo 'export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar'>>/etc/profile
echo 'export PATH=$PATH:$JAVA_HOME/bin'>>/etc/profile
export JAVA_HOME=/usr/java/jdk1.8.0_73/
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
# 解决JDK随机数问题导致tomcat启动异常缓慢的问题
sed -i "s#^securerandom.source=file:/dev/random#securerandom.source=file:/dev/./urandom#g" /usr/java/jdk1.8.0_73/jre/lib/security/java.security

# 下载Tomcat8并解压处理好
mkdir /readyFile/tomcat8
cd /readyFile/tomcat8
echo '下载Tomcat8'
wget http://down.zvo.cn/centos/apache-tomcat-8.5.90.zip
# 安装 unzip 命令
yum -y install unzip
unzip apache-tomcat-8.5.90.zip
cd webapps
rm -rf docs
rm -rf examples
rm -rf host-manager
rm -rf manager
cd ROOT
rm -rf ./*
# 将tomcat8移动到/mnt目录下
cd /readyFile
mv tomcat8/ /mnt/
# 将Tomcat8加入开机自启动
echo '将Tomcat8加入开机自启动'
echo 'JAVA_HOME=/usr/java/jdk1.8.0_73/'>>/etc/rc.local
echo 'export JAVA_HOME'>>/etc/rc.local
# 加入开机启动文件
echo '/mnt/tomcat8/bin/startup.sh'>>/etc/rc.d/rc.local
# 赋予可执行权限
chmod +x /mnt/tomcat8/bin/startup.sh
chmod +x /etc/rc.d/rc.local

#放开80端口访问权限
firewall-cmd --zone=public --add-port=80/tcp --permanent
#重新载入防火强
firewall-cmd --reload

# 环境准备结束
echo 'jdk、tomcat安装完成'

